<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

<fmt:setBundle basename="messages"/>

<script type="text/javascript">
	var validSubmit = true;
	
	function submitSaveEditVersion(form){
		
		if (validateEditVersionForm()){
			if (form.versionActive.checked){
				form.versionActive.value = true;
			} else {
				form.versionActive.value = false;
			}
			
			form.action = "saveEditVersion.do";

			form.submit();
		}
	}

	function submitCancel(form){
		if (validSubmit){
			validSubmit = false;
			form.action = "versionList.do";

			form.submit();
		}
	}
	
	function validateEditVersionForm(){
		var validForm = false;
		var versionCode = document.getElementById('versionCode').value;
		var versionDescription = document.getElementById('versionDescription').value;
		
		versionCode = trim(versionCode);
		versionDescription = trim(versionDescription);

		if (versionCode.length == 0){
			alert('<fmt:message key="warning.message.version.required.code"/>');
		} else if(versionDescription.length == 0){
			alert('<fmt:message key="warning.message.version.required.description"/>');
		} else {
			validForm = true;
		}

		return validForm;
	}
</script>

<form name="EditVersionForm" method="POST">
	<input type="hidden" name="versionView.versionId" value="<c:out value="${VersionForm.versionView.versionId}"/>"/>
	<table width="100%" align="center" border="0">
		<tr>
			<td style="width: 100%" align="center">
				<table style="width: 340" align="center" border="0" cellspacing="1" bgcolor="#CCCCC0">
					<tr>
						<th colspan="2" align="center" class="titulocolumna">
							<fmt:message key="label.versions.editVersion"/>
						</th>
					</tr>
					<tr>
						<td class="etiqueta" style="width: 35%">
							<fmt:message key="label.versions.startDate"/>
						</td>
						<td class="etiqueta_campo">
							<input type="text" value="<c:out value="${version.startDate}"/>" class="campo_texto" size="15" maxlength="5" disabled="disabled"/>
						</td>
					</tr>
					<tr>
						<td class="etiqueta" style="width: 35%">
							<fmt:message key="label.versions.endDate"/>
						</td>
						<td class="etiqueta_campo">
							<input type="text" value="<c:out value="${version.endDate}"/>" class="campo_texto" size="15" maxlength="5" disabled="disabled"/>
						</td>
					</tr>
					<tr>
						<td class="etiqueta" style="width: 35%">
							<fmt:message key="label.versions.code"/>
						</td>
						<td class="etiqueta_campo">
							<input type="text" name="versionView.shortName" id="versionCode" value="<c:out value="${version.shortName}"/>" class="campo_texto" size="15" maxlength="5"/>
						</td>
					</tr>
					<tr>
						<td class="etiqueta" style="width: 35%">
							<fmt:message key="label.versions.description"/>
						</td>
						<td class="etiqueta_campo">
							<input type="text" name="versionView.description" id="versionDescription" value="<c:out value="${version.description}"/>" class="campo_texto" size="15" maxlength="100"/>
						</td>
					</tr>
					<tr>
						<td class="etiqueta" style="width: 35%; height: 21px;">
							<fmt:message key="label.versions.importFrom"/>
						</td>
						<td class="etiqueta_campo">
							&nbsp;&nbsp;<c:out value="${parentVersion.parentShortName}"/> (<c:out value="${version.parentStartDate}"/> - <c:out value="${version.parentEndDate}"/>)
						</td>
					</tr>
					<tr>
						<td class="etiqueta" style="width: 35%">
							<fmt:message key="label.versions.active"/>
						</td>
						<td class="etiqueta_campo">
							<input type="checkbox" name="versionView.active" id="versionActive" <c:if test="${version.active}">CHECKED</c:if>/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="10">
			</td>
		</tr>
		<tr>
			<td width="100%">
				<table align="center" width="340" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
					<tr>
						<td style="text-align: center; vertical-align: bottom;" class="columnadatoPar">
							<input type="button" value="<fmt:message key="label.common.save"/>" onclick="submitSaveEditVersion(EditVersionForm);" class="boton"/>
							<input type="button" value="<fmt:message key="label.common.cancel"/>" onclick="submitCancel(EditVersionForm);" class="boton"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>